package com.yangxk.upload.starter;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.io.File;

@ConfigurationProperties(prefix = "fileupload")
public class UploadProperties {

    private UploadProperties.Disk disk = new UploadProperties.Disk();
    private UploadProperties.Ftp ftp = new UploadProperties.Ftp();

    public Disk getDisk() {
        return disk;
    }

    public Ftp getFtp() {
        return ftp;
    }

    // 磁盘存储相关配置
    public static class Disk {
        private static final String DEFAULT_DIR = System.getProperty("user.home") + File.separator + "k-admin";

        // 是否启用磁盘存储, 默认为true
        private boolean enabled=true;

        // 磁盘存储的目录, 默认为当前用户的家目录下的k-admin目录
        private String dir = DEFAULT_DIR;

        // 磁盘存储时的开始目录名称, 默认为"uploads"
        // diskDir和resourceMappingPrefix采用默认配置后文件最终存储位置: ${user.home}/k-admin/uploads/.../a.txt
        private String resourceMappingPrefix = "uploads";

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public String getDir() {
            return dir;
        }

        public void setDir(String dir) {
            this.dir = dir;
        }

        public String getResourceMappingPrefix() {
            return resourceMappingPrefix;
        }

        public void setResourceMappingPrefix(String resourceMappingPrefix) {
            if (resourceMappingPrefix.startsWith("/"))
                resourceMappingPrefix = resourceMappingPrefix.substring(1);

            this.resourceMappingPrefix = resourceMappingPrefix;
        }
    }

    // ftp相关配置
    public static class Ftp {
        // 是否启用ftp存储, 默认为false
        private boolean enabled=false;

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
    }

}
